package com.gzc.just.play.last.war.common.connection;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 消息编码器
 */
public class MessageEncoder extends MessageToByteEncoder<MessageDecoder.ServerMessage> {
    
    @Override
    protected void encode(ChannelHandlerContext ctx, MessageDecoder.ServerMessage msg, ByteBuf out) throws Exception {
        // 写入消息ID (4字节, 小端序)
        out.writeIntLE(msg.getMessageId());
        
        // 写入消息体
        out.writeBytes(msg.getData());
    }
}